package com.core.zyyz.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.core.common.utils.StringUtils;
import com.core.zyyz.amc.modules.domain.AmcProjectLibraryB;
import com.core.zyyz.amc.modules.domain.AmcProjectSubnode;
import com.core.zyyz.amc.modules.mapper.AmcProjectLibraryBMapper;
import com.core.zyyz.amc.modules.mapper.AmcProjectSubnodeMapper;
import com.core.zyyz.amc.modules.service.AmcProjectLibraryBService;
import com.core.zyyz.amc.modules.service.AmcProjectSubnodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * 生成表公共字段工具类
 */
@Component
public class PublicUtil {

    private static PublicUtil publicUtil;

    @Autowired
    private AmcProjectLibraryBService amcProjectLibraryBService;
    @Autowired
    private AmcProjectLibraryBMapper amcProjectLibraryBMapper;
    @Autowired
    private AmcProjectSubnodeMapper amcProjectSubnodeMapper;

    /**
     * 各业务节点回写项目进度字段至项目库
     */
    public void updateProjectProcess(String projectNumber, String businessNode) {
        if (StringUtils.isNotEmpty(projectNumber) && StringUtils.isNotEmpty(businessNode)) {
            AmcProjectLibraryB amcProjectLibraryB = amcProjectLibraryBMapper.selectProjectLibraryBByProjectNumber(projectNumber);
            amcProjectLibraryB.setProjectProcessCode(businessNode);
            //如果为授信时
            if ("creditAgreement1".equals(businessNode)||"creditAgreement2".equals(businessNode)){
                String subNodeName = "";
                if ("creditAgreement1".equals(businessNode)){
                    subNodeName = "银行授信登记";
                }else {
                    subNodeName = "监督机构批复";
                }
                amcProjectLibraryB.setProjectProcessName(subNodeName);
            } else {
                AmcProjectSubnode amcProjectSubnode = publicUtil.amcProjectSubnodeMapper.selectProjectSubnodeBySubNodeCode(businessNode);
                if (amcProjectSubnode != null) {
                    amcProjectLibraryB.setProjectProcessName(amcProjectSubnode.getSubnodeName());
                }
            }
            publicUtil.amcProjectLibraryBService.updateAmcProjectLibraryB(amcProjectLibraryB);
        }
    }
}
